package com.heima.admin.listener;

import com.alibaba.fastjson.JSON;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.model.common.constants.NewsAutoScanConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Description:
 * @Version: V1.0
 */
@Component
@Slf4j
public class WemediaNewsAutoListener {

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void recevieMessage(String message) {

        if (StringUtils.isNotBlank(message)) {
            log.info("WemediaNewsAutoListener recevieMessage:{}", message);
            // 解析消息
            Map<String, Integer> map = JSON.parseObject(message, Map.class);
            Integer wmNewsId = map.get("wmNewsId");

            wemediaNewsAutoScanService.autoScanByMediaNewsId(wmNewsId);

            log.info("*******文章自动审核成功*********");
        }
    }

}
